﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Gao.Poker.Services;
using Gao.Poker.ViewModel;

namespace Gao.Poker.App.Win
{
    /// <summary>
    /// Interaction logic for CompetitionManageWin.xaml
    /// </summary>
    public partial class CompetitionManageWin : Window
    {
        private readonly CompetitionViewModel _viewModel;
        private readonly CompetitionService cs;

        public CompetitionManageWin()
        {
            InitializeComponent();
            _viewModel = new CompetitionViewModel{Message = OnMessage};
            DataContext = _viewModel;
            cs = new CompetitionService();
        }

        private void OnMessage(string msg)
        {
            MessageBox.Show(msg, "提示信息");
        }

        private void Apply_Click(object sender, RoutedEventArgs e)
        {
            if (_viewModel.Competition.ID == 0)
            {
                OnMessage("请选择比赛");
                return;
            }

            _viewModel.Competition = cs.GetCompetition(_viewModel.Competition.ID);
            if (_viewModel.Competition.State == 1)
            {
                OnMessage("比赛以结束");
                return;
            }

            MemberWin win = new MemberWin();
            win.ViewModel = _viewModel;
            win.Competition = _viewModel.Competition;
            win.Show();
        }

        private void Buy_Click(object sender, RoutedEventArgs e)
        {
            if(_viewModel.Competition.ID == 0)
            {
                OnMessage("请选择比赛");
                return;
            }

            _viewModel.Competition = cs.GetCompetition(_viewModel.Competition.ID);
            if (_viewModel.Competition.State == 1)
            {
                OnMessage("比赛以结束");
                return;
            }

            BuyStakeWin win = new BuyStakeWin();
            win.ViewModel = _viewModel;
            win.Competition = _viewModel.Competition;
            win.Show();
        }

        private void End_Click(object sender, RoutedEventArgs e)
        {
            if (_viewModel.Competition.ID == 0)
            {
                OnMessage("请选择比赛");
                return;
            }
          
            _viewModel.Competition = cs.GetCompetition(_viewModel.Competition.ID);
            if(_viewModel.Competition.State == 1)
            {
                OnMessage("比赛以结束");
                return;
            }

            CompetitionEndWin win = new CompetitionEndWin();
            win.ViewModel = _viewModel;
            win.Competition = _viewModel.Competition;
            win.Show();
        }

        private void Bonus_Click(object sender, RoutedEventArgs e)
        {
            if (_viewModel.Competition.ID == 0)
            {
                OnMessage("请选择比赛");
                return;
            }

            _viewModel.Competition = cs.GetCompetition(_viewModel.Competition.ID);
            if (_viewModel.Competition.State == 1)
            {
                OnMessage("比赛以结束");
                return;
            }

            CompetitionBonusWin win = new CompetitionBonusWin();
            win.ViewModel = _viewModel;
            win.Competition = _viewModel.Competition;
            win.Show();
        }
    }
}
